import 'package:fish_redux/fish_redux.dart';
import 'action.dart';
import 'state.dart';
import '../../../app_files.dart';

Effect<OrderTransferViewState> buildEffect() {
  return combineEffects(<Object, Effect<OrderTransferViewState>>{
    OrderTransferViewAction.onSubmit: _onSubmit,
  });
}

void _onSubmit(Action action, Context<OrderTransferViewState> ctx) async {
  // if (ctx.state.selectWorker == null) {
  //   CommonUtils.showErrorInfo(ctx.context, '请选择接单的人员');
  //   return;
  // }
  if (ctx.state.contentController.text.length == 0) {
    CommonUtils.showErrorInfo(ctx.context, '请填写转单原因');
    return;
  }
  CommonUtils.showWaitLoading(ctx.context, descText: '提交中');
  ResultData res = await CommonNetWork.fixTransfer(
    ctx.state.itemID,
    ctx.state.contentController.text,
    // ctx.state.selectWorker.userID,
  );
  Navigator.pop(ctx.context);
  if (res.success) {
    bus.emit('refreshList');
    await CommonUtils.showAlertView(ctx.context, '转单申请提交成功');
    Navigator.popUntil(
        ctx.context, ModalRoute.withName('/'));
  } else {
    CommonUtils.showErrorInfo(ctx.context, res.desc);
  }
}
